package com.example.movedemo;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.VideoView;

import com.bumptech.glide.Glide;

import java.util.List;

/**
 * 作者：xuqing
 * 时间：
 * 邮箱：1693891473@qq.com
 * 说明：
 */
public class MyAdapter extends BaseAdapter {

    private List<VideoModel.DataBean> data;
    private Context context;


    public MyAdapter(List<VideoModel.DataBean> data, Context context) {
        this.data = data;
        this.context = context;
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int i) {
        return data.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHodler hodler = null;
        VideoModel.DataBean  dataBean=data.get(i);
        VideoModel.DataBean.VideoBean videoBean=dataBean.getVideo();
        VideoModel.DataBean.FirstFrameBean  firstFrameBean=dataBean.getFirstFrame();
        if (view == null) {
            view = LayoutInflater.from(context).inflate(R.layout.item, viewGroup, false);
            hodler =new ViewHodler();
            hodler.videoView=view.findViewById(R.id.video);
            hodler.imageView=view.findViewById(R.id.image);
            view.setTag(hodler);
        } else {
            hodler = (ViewHodler) view.getTag();
        }
        hodler.imageView.setVisibility(View.VISIBLE);
        Glide.with(context).load(firstFrameBean.getI1080()).into(hodler.imageView);
        ViewHodler finalHodler = hodler;
//        hodler.imageView.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                finalHodler.imageView.setVisibility(View.GONE);
//                finalHodler.videoView.setVisibility(View.VISIBLE);
//
//
//                finalHodler.videoView.setVideoPath(videoBean.getV1080());
//                finalHodler.videoView.requestFocus();
//                finalHodler.videoView.start();
//            }
//        });
        return view;
    }

    public  class  ViewHodler{
        VideoView videoView;
        ImageView imageView;
    }

    public  String  getvideoUlr(int position){
        VideoModel.DataBean  dataBean=data.get(position);
        VideoModel.DataBean.VideoBean videoBean=dataBean.getVideo();
        return  videoBean.getV1080();
    }

}
